class Solution {
    //这个代码是有问题的，没有修改
    public MySingleList.ListNode removeElements
            (MySingleList.ListNode head, int val) {
        //判断头节点为空
        if(head == null) { 
            return null;
        }
        //到这说明头节点不为空
        MySingleList.ListNode ret = head;
        MySingleList.ListNode cur = ret;
        MySingleList.ListNode curNext = ret.next;
        MySingleList.ListNode curPre = new MySingleList.ListNode(0);
        while(ret != null) {
            while(ret.next.val != val) {
                cur = ret;
                ret = ret.next;
                curNext = ret.next;
            }
            //找到val(若第一个是val，则删不掉)
            curPre.next = ret.next;
            ret = curNext;
            cur.next = ret;
            curNext = ret.next;
        }
        return curPre.next;
    }
}